// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1
import "../Components"

AndroidItem {
    id: _root
    width: 720 * viewScale
    height: 1134 * viewScale
    mouseAccepted: false
    clip: true
    color: Qt.rgba(0, 0, 0, _notifyArea.height / (_root.height * 1.2))

    visible: !isLock    //ロックされてる時は表示しない
    opacity: _notifyArea.height <= 0 ? 0 : 1    //表示するときしか表示しない

    property variant notificationItemNormalPath: []      //通知アイテム
    property variant notificationItemPressedPath: []     //通知アイテム
    property variant notificationTrackingBgPath: []      //通知背景

    property bool isViewing: false
    property real itemWidth: _root.width
    property real itemHeight: 128 * viewScale

    property alias viewHieght: _notifyArea.height       //外から高さを調整するためのエイリアス
    property bool handlePressed: false                  //外部から押してることにするためののフラグ

    property real moveToHeight: 0    // 移動先
    function moveTo(height){
        if(_anim.running){
            _anim.stop();
        }
        moveToHeight = height;
        _anim.start();
    }

    //表示
    onVisibleChanged: {

    }

    onHeightChanged: {
        //高さが変化したら回転した可能性あり
        if(viewHieght > 0){
            viewHieght = height;
        }
    }

    //この領域が縮んだりする
    Item{
        id: _notifyArea
        width: parent.width
        height: 0//parent.height
        clip: true

        //背景
        Image{
            id: _background
            anchors.fill: parent
            cache: false
            source: notificationTrackingBgPath[0]
        }

        //カレンダー表示している所
        Item{
            anchors.top: parent.top
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.bottom: _handleArea.top
            clip: true

            Rectangle{
                id: _topArea
                width: _root.width
                height: 92 * viewScale
                gradient: Gradient{
                    GradientStop{ position: 0; color: "#ff000000" }
                    GradientStop{ position: 0.5; color: "#ff000000" }
                    GradientStop{ position: 1; color: "#00000000" }
                }

                Row{
                    height: parent.height
                    spacing: 4
                    Item{
                        width: 4
                        height: 1
                    }

                    ImageClock{
                        id: _clock
                        anchors.verticalCenter: parent.verticalCenter

                        height: 46 * viewScale

                        clockNumberWidth: 26 * viewScale
                        clockColonWidth: 26 * viewScale
                        spacing: 4 * viewScale

                        numberPics: new Array("images/noti_num_0.png"
                            , "images/noti_num_1.png"
                            , "images/noti_num_2.png"
                            , "images/noti_num_3.png"
                            , "images/noti_num_4.png"
                            , "images/noti_num_5.png"
                            , "images/noti_num_6.png"
                            , "images/noti_num_7.png"
                            , "images/noti_num_8.png"
                            , "images/noti_num_9.png"
                                    )
                        colonPic: "images/noti_num_c.png"
                    }

                    LockScreenCalendar{
                        anchors.verticalCenter: parent.verticalCenter

                        numberPics: new Array("images/lock_num_s_0.png"
                                    , "images/lock_num_s_1.png"
                                    , "images/lock_num_s_2.png"
                                    , "images/lock_num_s_3.png"
                                    , "images/lock_num_s_4.png"
                                    , "images/lock_num_s_5.png"
                                    , "images/lock_num_s_6.png"
                                    , "images/lock_num_s_7.png"
                                    , "images/lock_num_s_8.png"
                                    , "images/lock_num_s_9.png"
                                    )
                        weekdayPics: new Array("images/lock_week_sun.png"
                                               , "images/lock_week_mon.png"
                                               , "images/lock_week_tsu.png"
                                               , "images/lock_week_wed.png"
                                               , "images/lock_week_thu.png"
                                               , "images/lock_week_fri.png"
                                               , "images/lock_week_sat.png"
                                               )
                        yearStrPic: "images/lock_year.png"
                        monthStrPic: "images/lock_week_mon.png"
                        dayStrPic: "images/lock_week_sun.png"
                        lcStrPic: "images/lock_calendar_lC.png"
                        rcStrPic: "images/lock_calendar_RC.png"
                        isViewYear: true
                        isWrap: true
                        isViewC: false
                    }

                    //設定画面へのボタン
                    ImageButton{
                        anchors.verticalCenter: parent.verticalCenter

                        width: 64 * viewScale
                        height: 64 * viewScale
                        imageIdle: "../Android/images/SystemUI/ic_notify_quicksettings_normal.png"
                        imagePress: "../Android/images/SystemUI/ic_notify_quicksettings_pressed.png"
                    }
                }

                //通知を消すボタン
                ImageButton{
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.right: parent.right
                    width: 64 * viewScale
                    height: 64 * viewScale
                    imageIdle: "../Android/images/SystemUI/ic_notify_clear_normal.png"
                    imagePress: "../Android/images/SystemUI/ic_notify_clear_pressed.png"
                }
            }


            //通知のバー
            Item{
                anchors.top: _topArea.bottom
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.bottom: parent.bottom
                clip: true

                Column{
                    anchors.bottom: parent.bottom
                    anchors.bottomMargin: 6 * viewScale

                    //２つめのアイテム
                    Item{
                        width: itemWidth
                        height: itemHeight
                        ImageButton {
                            id: _item2
                            width: itemWidth
                            height: itemHeight
                            imageIdle: notificationItemNormalPath[0]
                            imagePress: notificationItemPressedPath[0]
                        }
                        Image {
                            width: itemHeight
                            height: itemHeight
                            source: "images/notification_item_icon.png"
                        }
                    }

                    //隙間
                    Item{
                        width: itemWidth
                        height: 12 * viewScale
                    }

                    //１つめのアイテム
                    ImageButton {
                        id: _item1
                        width: itemWidth
                        height: itemHeight
                        imageIdle: notificationItemNormalPath[0]
                        imagePress: notificationItemPressedPath[0]
                    }

                }
            }
        }


        //つかむところ
        Item{
            id: _handleArea
            anchors.bottom: parent.bottom
            width: _root.width
            height: 36 * viewScale
            Rectangle{
                //anchors.horizontalCenter: parent.horizontalCenter
                anchors.left: parent.left
                anchors.leftMargin: 28 * viewScale
                anchors.right: parent.right
                anchors.rightMargin: 28 * viewScale
//                y: 0 * viewScale
//                width: 664 * viewScale
                height: 8 * viewScale
                color: (_handleMouseArea.pressed || _root.handlePressed) ? "#33b5e5" : "#66ffffff"
            }
            MouseArea{
                id: _handleMouseArea
                anchors.fill: parent
                property real prev_y: 0
                onPressed: {
                    prev_y = mouse.y;
                }
                onMousePositionChanged: {
                    var temp = (mouse.y - prev_y) * viewScale;
                    if((_notifyArea.height + temp) > _root.height){
                    }else{
                        _notifyArea.height += temp;
                    }
                }
                onReleased: {
                    if((_notifyArea.height / _root.height) > 0.9){
                        //広げる
                        _root.moveTo(_root.height);
                    }else{
                        //縮める
                        _root.moveTo(0);
                    }
                }
            }
        }
    }



    NumberAnimation {
        id: _anim
        target: _notifyArea
        property: "height"
        to: moveToHeight
        duration: 400
        easing.type: Easing.InOutQuad
        running: false
    }


    states: [
        State {
            name: "Land"
            when: !isPortrait
            PropertyChanges {
                target: _background
                source: _root.notificationTrackingBgPath[1]
            }
            PropertyChanges {
                target: _item1
                imageIdle: _root.notificationItemNormalPath[1]
                imagePress: _root.notificationItemPressedPath[1]
            }
            PropertyChanges {
                target: _item2
                imageIdle: _root.notificationItemNormalPath[1]
                imagePress: _root.notificationItemPressedPath[1]
            }
        }
    ]
}
